//
//  EnterpriseGuidDetailController.m
//  homeland
//
//  Created by Alawn on 13-11-15.
//  Copyright (c) 2013年 xzysun. All rights reserved.
//

#import "EnterpriseGuidDetailController.h"
#import "StreetGuidDetailInfoCell.h"
#import "MYGuideCommonDetailService.h"

#define DETAIL_TEXTVIEW_WIDTH 190.0
@interface EnterpriseGuidDetailController ()
@property (nonatomic, strong) MYGuideCommonDetailService *detailServer;

@end

@implementation EnterpriseGuidDetailController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"指南详情";
    if (self.item==nil) {
        self.item = [_config objectForKey:@"dataItem"];
        if (self.item != nil) {
            self.detailServer = [[MYGuideCommonDetailService alloc] init];
            self.detailServer.delegate = self;
            self.detailServer.dataType = self.item.dataType;
            [self.detailServer loadDataWithKey:self.item.Id];
            self.tableView.delegate = nil;
            self.tableView.dataSource = nil;
        }
        
    }
}


#pragma mark - Data Service
-(void)loadDataFinished
{
    if (self.detailServer.dataList.count > 0) {
        self.item = self.detailServer.dataList[0];
    }
    [self stopLoadingView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;

    [self.tableView reloadData];
}

-(void)loadDataFaild:(NSString *)msg
{
    [self stopLoadingView];
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"错误" message:msg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - Table Method
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 9;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    StreetGuidDetailInfoCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"StreetGuidDetailInfoCell" owner:self options:nil] objectAtIndex:0];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.titleLabel.contentInset = UIEdgeInsetsMake(-8, -8, -8, -8);
    cell.detailTextView.contentInset = UIEdgeInsetsMake(-8, -8, -8, -8);
    cell.titleLabel.clipsToBounds = NO;
    cell.detailTextView.clipsToBounds = NO;
    if (indexPath.row == 0) {
        cell.titleLabel.text = @"事项名称";
        cell.detailTextView.text = _item.respectiveIssue;
    } else if (indexPath.row == 1){
        cell.titleLabel.text = @"事件编号";
        cell.detailTextView.text = _item.itemCode;
    } else if (indexPath.row == 2){
        cell.titleLabel.text = @"受理部门";
        cell.detailTextView.text = _item.acceptUnit ;
    } else if (indexPath.row == 3){
        cell.titleLabel.text = @"审批流程";
        cell.detailTextView.text = @"";
    } else if (indexPath.row == 4){
        cell.titleLabel.text = @"所需材料";
        cell.titleLabel.frame = CGRectMake(10, 13, 100, 36);
        cell.detailTextView.text = _item.recStuff;
    } else if (indexPath.row == 5){
        cell.titleLabel.frame = CGRectMake(10, 13, 100, 36);
        cell.titleLabel.text = @"审批依据";
        cell.detailTextView.text = _item.approvalBasedOn;
    } else if (indexPath.row == 6){
        cell.titleLabel.text = @"收费标准";
        cell.detailTextView.text = _item.approveAim;
    } else if (indexPath.row == 7){
        cell.titleLabel.frame = CGRectMake(10, 13, 100, 36);
        cell.titleLabel.text = @"办理时限";
        cell.detailTextView.text = _item.timeLimit;
    } else if (indexPath.row == 8){
        cell.titleLabel.frame = CGRectMake(10, 13, 100, 36);
        cell.titleLabel.text = @"法定时限";
        cell.detailTextView.text = _item.legalForTime;
    }
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        CGFloat height = [self caculateHeightWithoutPaddingForString:_item.respectiveIssue AndFontSize:17.0 AndWitdh:DETAIL_TEXTVIEW_WIDTH];
        return MAX(44.0, height+26.0);
    }
    if (indexPath.row == 3) {
        CGFloat height = [self caculateHeightWithoutPaddingForString:_item.acceptUnit AndFontSize:17.0 AndWitdh:DETAIL_TEXTVIEW_WIDTH];
        return MAX(44.0, height+26.0);
    }
    if (indexPath.row == 4) {
        CGFloat height = [self caculateHeightWithoutPaddingForString:_item.recStuff AndFontSize:17.0 AndWitdh:DETAIL_TEXTVIEW_WIDTH];
        return MAX(44.0, height+26.0);
    }
    if (indexPath.row == 5) {
        CGFloat height = [self caculateHeightWithoutPaddingForString:_item.approvalBasedOn AndFontSize:17.0 AndWitdh:DETAIL_TEXTVIEW_WIDTH];
        return MAX(44.0, height+26.0);
    }
    if (indexPath.row == 6) {
        CGFloat height = [self caculateHeightWithoutPaddingForString:_item.approveAim AndFontSize:17.0 AndWitdh:DETAIL_TEXTVIEW_WIDTH];
        return MAX(44.0, height+26.0);
    }
//    if (indexPath.row == 7) {
//        return 44.0;
//    }
//    if (indexPath.row == 8) {
//        return 44.0;
//    }
    return 44.0;
}
@end
